<?php


namespace library;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;

class Monolog
{
    public static function getLogger($logName = 'system')
    {
        $dateFormat = "Y-m-d H:i:s";
        $output = "[%datetime%] [%pid%] %channel%.%level_name%: %message% %context%\n"; // 输出格式

        $formatter = new LineFormatter($output, $dateFormat);
        $stream = new RotatingFileHandler(ROOT_PATH.'/runtime/log/system.log', 10,\Monolog\Logger::DEBUG);
        $stream->setFormatter($formatter);

        $logger = new Logger($logName);
        $logger->pushHandler($stream);

        $logger->pushProcessor(function ($record) {
            $record['pid'] = posix_getpid();
            return $record;
        });

        return $logger;
    }



}